package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.ZhxTopic;
import com.ruoyi.admin.service.IZhxTopicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 话题管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/ZhxAdmin/ZhxTopic")
public class ZhxTopicController extends BaseController
{
    @Autowired
    private IZhxTopicService zhxTopicService;

    /**
     * 查询话题管理列表
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhxTopic zhxTopic)
    {
        startPage();
        List<ZhxTopic> list = zhxTopicService.selectZhxTopicList(zhxTopic);
        return getDataTable(list);
    }

    /**
     * 导出话题管理列表
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:export')")
    @Log(title = "话题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhxTopic zhxTopic)
    {
        List<ZhxTopic> list = zhxTopicService.selectZhxTopicList(zhxTopic);
        ExcelUtil<ZhxTopic> util = new ExcelUtil<ZhxTopic>(ZhxTopic.class);
        util.exportExcel(response, list, "话题管理数据");
    }

    /**
     * 获取话题管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:query')")
    @GetMapping(value = "/{topicId}")
    public AjaxResult getInfo(@PathVariable("topicId") Long topicId)
    {
        return success(zhxTopicService.selectZhxTopicByTopicId(topicId));
    }

    /**
     * 新增话题管理
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:add')")
    @Log(title = "话题管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhxTopic zhxTopic)
    {
        return toAjax(zhxTopicService.insertZhxTopic(zhxTopic));
    }

    /**
     * 修改话题管理
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:edit')")
    @Log(title = "话题管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhxTopic zhxTopic)
    {
        return toAjax(zhxTopicService.updateZhxTopic(zhxTopic));
    }

    /**
     * 删除话题管理
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:remove')")
    @Log(title = "话题管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topicIds}")
    public AjaxResult remove(@PathVariable Long[] topicIds)
    {
        return toAjax(zhxTopicService.deleteZhxTopicByTopicIds(topicIds));
    }
}
